package cn.rengy.web.excelcompare.service;

import cn.rengy.isql.Dao;
import cn.rengy.lang.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ExcelConfigService {

    @Autowired
    private Dao dao;

    @Autowired
    private ExcelCompareConfigService excelCompareConfigService;
    @Transactional(rollbackFor = Exception.class)
    public ResultEntity delete(Long id){
        //1.删除 表头 excel_header
        dao.update("delete from excel_header where excel_config_id=?",id);
        //2.删除title excel_column_title
        dao.update("delete from excel_column_title where report_id=?",id);
        //3.删除比较定义
        List<Long> compareIdList=dao.querySingleColumnForList("select distinct c.id from excel_compare_config_detail cd join excel_compare_config c on c.id=cd.compare_config_id where cd.report_id=?",Long.class,id);
        for(Long compareId:compareIdList){
            excelCompareConfigService.deleteById(compareId);
        }
        //4.最后删除 excel_config
        dao.update("delete from excel_config where id=?",id);
        return ResultEntity.ok();
    }
}
